package com.example.scancodelogindemo.model;

import com.example.scancodelogindemo.enums.StatusCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@AllArgsConstructor
@Builder
public class Result<T> {
    private String code;//返回码
    private String message;//返回消息
    private T data;//返回数据

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.code = StatusCodeEnum.OK.getCode();
        this.message = StatusCodeEnum.OK.getMsg();
    }

    public static Result<Void> ok() {
        return new Result<>();
    }

    public static <T> Result<T> ok(T data) {
        return new Result<>(StatusCodeEnum.OK.getCode(), StatusCodeEnum.OK.getMsg(), data);
    }

    public static Result<Void> error(String msg) {
        return new Result<>(StatusCodeEnum.ERROR.getCode(), msg);
    }

    public static Result<Void> error(String code,String msg) {
        return new Result<>(code, msg);
    }
}
